require(['./config'],()=>{
	require(['cookie','footer'],()=>{
		class Register{
			constructor() {
			   this.test() 
			   this.register()
			   
			}
			test(){
				  var flag1=true
				  $('.login-name').on('blur',function(){
					  checkUser()
				  })
				  function checkUser(){
					  const username = $('.login-name').val()
					  var re = /^[0-9A-Za-z]{2,8}$/
					  if(username === ''){
						  $('.login-name').next().show().html('用户名不能为空')
						  flag1=false
					  }else if(re.test(username)){
						   $('.login-name').next().hide()
						   flag1=true
					  }else{
						  $('.login-name').next().show().html('格式有误')
						  flag1=false
					  }
				  }
				  $('.login-pass').on('blur',function(){
					  checkPass()
				  })
				  function checkPass(){
					  var password = $('.login-pass').val()
					  var req=/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/
					  if(password === ''){
					  	$('.login-pass').next().show().html('密码不能为空')
					  	flag1=false
					  }else if(req.test(password)){
					    $('.login-pass').next().hide()
					    flag1=true
					  }else{
					    $('.login-pass').next().show().html('格式有误')
					    flag1=false
					  }
				  }
				  $('.confirm-pass').on('blur',function(){
					checkPre()
				  })
				  function checkPre(){
					//   var val = $('.login-pass').val()
				 	  var repass = $('.confirm-pass').val()
					  if(repass === ''){
						  $('.confirm-pass').next().show().html('密码不能为空')
						  return false
					  }
					  if(repass != password){
						  $('.confirm-pass').next().show().html('与原密码不一致')
						  return false
					  }
					  if(repass === password){
						  alert('注册成功')
						  return true
					  }
					  
					
				  }
				
			}
			register(){
				$('.btn').on('click',function(){
					var username = $('.login-name').val()				
					var password = $('.login-pass').val()				
					var userinfo = {username,password}		
					var userList = localStorage.getItem('userList')
					if(userList){	
						userList = JSON.parse(userList)
						userList.push(userinfo)
					     localStorage.setItem('userList',JSON.stringify(userList))
					}else{
						var arr=[userinfo]
						localStorage.setItem('userList',JSON.stringify(arr))
					}
					alert('注册成功，即将跳转登录页')
                   location.href = 'login.html'
				})
			}
		}
		new Register()
	})
})